<!--
 * @Author: canlong.shen
 * @Date: 2021-11-02 10:21:43
 * @LastEditors: your name
 * @LastEditTime: 2021-11-02 14:48:04
 * @Description: file content
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>计算属性的setter</title></title>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="https://unpkg.com/vue@next"></script>
  </head>
  <body>
    <div id="root"></div>
    <script>
      const app =   Vue.createApp({
        data() {
          return {
            count:1000,
            firstName : '沈',
            lastName : '灿龙',
          }
        },
        computed : {
           fullName :{

            get(){
              return this.firstName +" "+ this.lastName
            },
            set(newValue){
              console.log(newValue)
              const names = newValue.split(' ')
            this.firstName = names[0]
            this.lastName = names[names.length - 1]
            }

           }
        },
        template: `
          <div>
          {{fullName}}
          {{firstName}}
          {{lastName}}
          </div>`,
      }) 
      
      const vm  =  app.mount("#root")
      vm.fullName = "愚蠢 地球人"
    </script>
  </body>
</html>
